package cn.lx.elasticsearch.autocomplete.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.core.completion.Completion;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品实体类 - 用于演示自动补全功能
 * 
 * @author lx
 * @since 2024-01-01
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "products")
public class Product {

    @Id
    private String id;

    /**
     * 商品名称 - 用于自动补全
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String name;

    /**
     * 自动补全字段 - 真正的 completion 字段
     */
    @CompletionField(maxInputLength = 100)
    private Completion nameSuggest;

    /**
     * 商品描述
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word")
    private String description;

    /**
     * 商品价格
     */
    @Field(type = FieldType.Double)
    private BigDecimal price;

    /**
     * 商品分类
     */
    @Field(type = FieldType.Keyword)
    private String category;

    /**
     * 商品标签
     */
    @Field(type = FieldType.Keyword)
    private List<String> tags;

    /**
     * 品牌
     */
    @Field(type = FieldType.Keyword)
    private String brand;

    /**
     * 库存数量
     */
    @Field(type = FieldType.Integer)
    private Integer stock;

    /**
     * 商品状态：1-上架，0-下架
     */
    @Field(type = FieldType.Integer)
    private Integer status;

    /**
     * 创建时间
     */
    @Field(type = FieldType.Date, format = DateFormat.date)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Field(type = FieldType.Date, format = DateFormat.date)
    private LocalDateTime updateTime;

    /**
     * 商品评分
     */
    @Field(type = FieldType.Double)
    private Double rating;

    /**
     * 销量
     */
    @Field(type = FieldType.Long)
    private Long sales;
}
